#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 1e9 + 10;
int a[N];
int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		long long x, y;
		scanf("%lld%lld", &x, &y);
		if (y >= x)
		{
			long long ans = 0;
			if (y % 2 != 0) ans = pow(y, 2);
			else ans = pow(y - 1, 2) + 1;
			if (y % 2 != 0)
				printf("%lld\n", ans - x + 1);
			else if (y % 2 == 0)
				printf("lld\n", ans + x - 1);
		}
		else
		{
			long long ans = 0;
			int t = 1, cur = 3;
			for (int i = 1; i <= x; ++i)
			{
				a[i] = t;
				t += cur;
				cur += 2;
			}
			if (x % 2 == 0) ans = a[x];
			else ans = a[x - 1] + 1;
			if (x % 2 != 0)
				printf("%lld\n", ans + y - 1);
			else if (x % 2 == 0)
				printf("%lld\n", ans - y + 1);
		}
	}
	return 0;
}